package team.kirohuji.message;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

import team.kirohuji.message.entity.Email;
import team.kirohuji.message.entity.EmailContent;
import team.kirohuji.message.utils.MailUtils;
import team.kirohuji.service.impl.EmailServiceImpl;



public class EmailMessageListener implements MessageListener {
	@Resource
	private EmailServiceImpl emailService;
    public void onMessage(Message message) {
        if (message instanceof TextMessage) {
            TextMessage textMessage = (TextMessage) message;
            try {
                String text = textMessage.getText();
                EmailContent emailContent=new EmailContent();
                emailContent.setContent("测试的内容");
                emailContent.setSubject("捕获到了404网页!");
                emailContent.setSendDate(new Date());
                List<Email> sendEmailList=emailService.queryAll();
                MailUtils.getInstance().sendMail(sendEmailList, emailContent);
            } catch (JMSException e) {
                e.printStackTrace();
            }
        }
    }

}